package com.project.lk.nurseapp.ticket;

import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.View;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.base.BaseActivity;
import com.project.lk.nurseapp.base.UrlContants;
import com.project.lk.nurseapp.ticket.model.ITicketBeanInfo;
import com.project.lk.nurseapp.ticket.model.TicketItemBean;
import com.project.lk.nurseapp.ticket.presenter.ITicketView;
import com.project.lk.nurseapp.ticket.presenter.TicketPresenter;
import com.project.lk.nurseapp.utils.AppManager;
import com.project.lk.nurseapp.utils.ToastUtils;
import com.project.lk.nurseapp.utils.XViewSettingUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class TicketActivity extends BaseActivity implements ITicketView {


    @BindView(R.id.xrecyclerview)
    XRecyclerView xrecyclerview;
    private TicketPresenter presenter;
    private TicketListAdapter adapter;
    private List<TicketItemBean> ticketItemBeanList;
    private String ticketType;

    @Override
    protected void initData() {
        ticketType = getIntent().getStringExtra("ticket");
        presenter = new TicketPresenter(this);
        presenter.refresh(UrlContants.TICKET_LIST_URL);
        adapter = new TicketListAdapter(presenter.getList(),this);
        LinearLayoutManager manager=new LinearLayoutManager(this);
        XViewSettingUtils.setting(xrecyclerview,adapter,manager);
    }

    @Override
    protected void initView() {


            adapter.setItemClick(new TicketListAdapter.OnItemClickListener() {
                @Override
                public void setOnItemClickListener(int position, View view) {
                    if (TextUtils.equals(ticketType,"pay")){
                        ToastUtils.showShortToast(position+">>>>>");
                        EventBus.getDefault().post(new ITicketBeanInfo(ticketItemBeanList.get(position)));
                    }
                }
            });

    }
    @Override
    protected int getLayoutId() {
        return R.layout.activity_ticket;
    }


    @Override
    public void showList() {
        if (adapter!=null) {
            ticketItemBeanList = presenter.getList();
            adapter.notifyDataSetChanged();
            xrecyclerview.refreshComplete();
            xrecyclerview.loadMoreComplete();
        }

    }

    @Override
    public void noMore() {
        if (xrecyclerview!=null) {
            xrecyclerview.refreshComplete();
            xrecyclerview.loadMoreComplete();
        }
    }

    @Override
    public void fail() {
        if (xrecyclerview!=null) {
            xrecyclerview.refreshComplete();
            xrecyclerview.loadMoreComplete();
        }
    }


    @OnClick(R.id.back)
    public void onViewClicked() {
        AppManager.getAppManager().finishActivity();
    }
}
